#!/bin/bash

set -o errexit
set -o xtrace

test_dir=$(realpath $(dirname $0))
. ${test_dir}/../functions

main() {
    create_infra $namespace

    cluster="some-name"
    spinup_pxc "$cluster" "$conf_dir/$cluster.yml"
    keyring_plugin_must_not_be_in_use "$cluster"
    table_must_not_be_encrypted "$cluster" "myApp"

    run_backup         "$cluster" "on-demand-backup-pvc"
    if [ -z "$SKIP_BACKUPS_TO_AWS_GCP" ]; then
        run_backup         "$cluster" "on-demand-backup-aws-s3"
    fi

    vault1="vault-service-1-${RANDOM}"
    start_vault $vault1
    run_recovery_check "$cluster" "on-demand-backup-pvc"
    check_pvc_md5
    keyring_plugin_must_be_in_use "$cluster"
    table_must_not_be_encrypted "$cluster" "myApp"

    if [ -z "$SKIP_BACKUPS_TO_AWS_GCP" ]; then
        run_recovery_check "$cluster" "on-demand-backup-aws-s3"
        keyring_plugin_must_be_in_use "$cluster"
        table_must_not_be_encrypted "$cluster" "myApp"
    fi

    helm delete $vault1 || :
    kubectl_bin delete --grace-period=0 --force=true namespace $vault1 &
    destroy $namespace
}

main
